package com.copa.module.goods.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.copa.annotation.Log;
import com.copa.domain.PageVo;
import com.copa.domain.ResponseDto;
import com.copa.module.goods.domain.dto.GoodsDetailDto;
import com.copa.module.goods.domain.dto.GoodsDto;
import com.copa.module.goods.domain.vo.GoodsAddVo;
import com.copa.module.goods.domain.vo.GoodsListVo;
import com.copa.module.goods.domain.vo.GoodsUpdateVo;
import com.copa.module.goods.service.GoodsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotNull;

/**
 * @author copa
 * @createDate 2021-01-08 12:07
 * @function
 */
@RestController
@Api(tags = {"商品接口"})
public class GoodsController {

    @Autowired
    private GoodsService goodsService;

    @Log("添加商品")
    @PostMapping("/goods/add")
    @ApiOperation("添加商品")
    public ResponseDto<String> add(@RequestBody GoodsAddVo goodsAddVo) {
        return goodsService.addGoods(goodsAddVo);
    }

    @PostMapping("/goods/list")
    @ApiOperation("商品列表")
    public ResponseDto<IPage<GoodsDto>> list(@RequestBody GoodsListVo goodsListVo) {
        return goodsService.list(goodsListVo.getPageVo(), goodsListVo.getGoodsName());
    }

    @PostMapping("/goods/detail")
    @ApiOperation("商品详情")
    public ResponseDto<GoodsDetailDto> detail(@RequestBody Long goodsId) {
        return goodsService.detail(Long.valueOf(goodsId));
    }

    @Log("修改商品")
    @PostMapping("/goods/put")
    @ApiOperation("修改商品")
    public ResponseDto<String> put(@RequestBody GoodsUpdateVo goodsUpdateVo) {
        return goodsService.put(goodsUpdateVo);
    }
}
